home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / a_to_d / delftips / ti2859.asc < prev    next >
Encoding:
Text File  |  1996-09-15  |  1.8 KB  |  122 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Delphi                                 NUMBER  :  2859
  8.   VERSION  :  All
  9.        OS  :  Windows
  10.      DATE  :  August 23, 1995                          PAGE  :  1/2
  11.  
  12.     TITLE  :  How to do bit-wise manipulation.
  13.  
  14.  
  15.  
  16.  
  17. Q:  How do I do bit-wise manipulation?
  18.  
  19. A:
  20.  
  21. {******************************************
  22. TheBit parameter is counted from 0..31
  23. ******************************************}
  24.  
  25. unit Bitwise;
  26.  
  27. interface
  28.   function IsBitSet(const val: longint; const TheBit: byte): boolean;
  29.   function BitOn(const val: longint; const TheBit: byte): LongInt;
  30.   function BitOff(const val: longint; const TheBit: byte): LongInt;
  31.   function BitToggle(const val: longint; const TheBit: byte): LongInt;
  32.  
  33.  
  34.  
  35. implementation
  36.  
  37. function IsBitSet(const val: longint; const TheBit: byte): boolean;
  38. begin
  39.   result := (val and (1 shl TheBit)) <> 0;
  40. end;
  41.  
  42. function BitOn(const val: longint; const TheBit: byte): LongInt;
  43. begin
  44.   result := val or (1 shl TheBit);
  45. end;
  46.  
  47. function BitOff(const val: longint; const TheBit: byte): LongInt;
  48. begin
  49.   result := val and ((1 shl TheBit) xor $FFFFFFFF);
  50. end;
  51.  
  52. function BitToggle(const val: longint; const TheBit: byte): LongInt;
  53. begin
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.   PRODUCT  :  Delphi                                 NUMBER  :  2859
  69.   VERSION  :  All
  70.        OS  :  Windows
  71.      DATE  :  August 23, 1995                          PAGE  :  2/2
  72.  
  73.     TITLE  :  How to do bit-wise manipulation.
  74.  
  75.  
  76.  
  77.  
  78.   result := val xor (1 shl TheBit);
  79. end;
  80.  
  81. end.
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. DISCLAIMER: You have the right to use this technical information
  119. subject to the terms of the No-Nonsense License Statement that
  120. you received with the Borland product to which this information
  121. pertains.
  122.